package com.by.utils;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class XmlUtils {
    public static Map<String, String> xmlToMap(String xml) {
        try {
            Map<String, String> map = new HashMap<>();
            Document document = DocumentHelper.parseText(xml);
            Element root = document.getRootElement();
            for (Iterator<Element> it = root.elementIterator(); it.hasNext();) {
                Element element = it.next();
                map.put(element.getName(), element.getText());
            }
            return map;
        } catch (Exception e) {
            throw new RuntimeException("XML 解析失败", e);
        }
    }
}
